#include "ScnsKey.c.h"

#if defined(SCNS_KEY_ENABLE)&&SCNS_KEY_ENABLE==1

#include "ScnsMenu.h"
#include "ScnsBeep.h"
#include "ScnsJoystick.h"

static void handler(ScnsKeyMsg key)
{
    if(key.status==SCNS_KEY_PRESS_DOWN)
        switch(key.key)
        {
            case SCNS_KEY_LJL:scnsBeepAdd("1");
                break;
            case SCNS_KEY_LJR:scnsBeepAdd("2");
                break;
            case SCNS_KEY_LJU:scnsBeepAdd("3");
                break;
            case SCNS_KEY_LJD:scnsBeepAdd("4");
                break;
            
            case SCNS_KEY_LJS:scnsBeepAdd("5");
                break;
            
            case SCNS_KEY_R1:scnsBeepAdd("6");
                break;
            case SCNS_KEY_R2:scnsBeepAdd("7");
                break;
            case SCNS_KEY_L1:scnsBeepAdd("!");
                break;
            case SCNS_KEY_L2:scnsBeepAdd("@");
                break;
            default:break;
        }
}

void blockKey(ScnsKeyMsg key)
{
    static uint8 last=1;
    if(key.status==SCNS_KEY_PRESS_HOLD)
    {
        scnsJoystickBlockKey(SCNS_JOYSTICK_L,last);
        scnsJoystickBlockKey(SCNS_JOYSTICK_R,last);
        last=!last;
        scnsBeepAdd("s");
    }
}

extern void startCallBack(ScnsKeyMsg keyMsg);

const ScnsBspKeyConfig scnsBspKeyConfig[SCNS_KEY_MAX]={
    {.name="R1 ",.callbacks=(void (*[])(ScnsKeyMsg)){handler,blockKey,NULL}},
    {.name="R2 ",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
    
    {.name="RJS",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="RJL",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="RJR",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="RJD",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="RJU",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    
    {.name="L1 ",.callbacks=(void (*[])(ScnsKeyMsg)){handler,startCallBack,NULL}},
    {.name="L2 ",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
    
    {.name="LJS",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
    {.name="LJL",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
    {.name="LJR",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
    {.name="LJD",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
    {.name="LJU",.callbacks=(void (*[])(ScnsKeyMsg)){handler,NULL}},
};

ScnsStatus scnsBspKeyInit(void)
{
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspKeyPostInit(void)
{
    return SCNS_STATUS_OK;
}

#endif